# Contributor: Bradley J Chambers <brad.chambers@gmail.com>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=pdal
pkgver=2.8.0
pkgrel=0
pkgdesc="PDAL is a C++ BSD library for translating and manipulating point cloud data."
url="https://pdal.io/"
arch="all"
license="BSD-2-Clause"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	cmake
	cpd-dev
	curl-dev
	eigen-dev
	fgt-dev
	gdal-dev
	hdf5-dev
	libgeotiff-dev
	libpq-dev
	libxml2-dev
	linux-headers
	openscenegraph-dev
	openssl-dev>3
	proj-dev
	py3-numpy-dev
	python3-dev
	samurai
	sqlite-dev
	zstd-dev
	xerces-c-dev
	"
checkdepends="gdal-tools gdal-driver-PNG gdal-driver-JPEG"
subpackages="
	$pkgname-dev
	libpdal-plugins
	"
source="https://github.com/PDAL/PDAL/releases/download/$pkgver/PDAL-$pkgver-src.tar.bz2"
builddir="$srcdir/PDAL-$pkgver-src"

case "$CARCH" in
	s390x)
		# 95% tests passed, 6 tests failed out of 110
		options="!check"
		;;
esac

build() {
	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_PLUGIN_CPD=ON \
		-DBUILD_PLUGIN_NITF=OFF \
		-DBUILD_PLUGIN_ICEBRIDGE=ON \
		-DBUILD_PLUGIN_HDF=ON \
		-DBUILD_PLUGIN_OPENSCENEGRAPH=ON \
		-DBUILD_PLUGIN_E57=ON \
		-DBUILD_PLUGIN_PGPOINTCLOUD=ON \
		-DBUILD_PLUGIN_RIVLIB=OFF \
		-DBUILD_PLUGIN_RDBLIB=OFF \
		-DBUILD_PLUGIN_MBIO=ON \
		-DBUILD_PLUGIN_FBX=ON \
		-DBUILD_PLUGIN_TEASER=OFF \
		-DBUILD_PLUGIN_TRAJECTORY=OFF \
		-DBUILD_PGPOINTCLOUD_TESTS=OFF \
		-DWITH_ZSTD=ON \
		-DWITH_TESTS="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

check() {
	# skipped tests are broken
	local skipped_tests="pdal_("
	local tests="
		filters_colorinterp
		filters_cpd
		filters_crop
		filters_overlay
		filters_stats
		io_bpf_base
		io_bpf_zlib
		io_ept_reader
		io_las_reader
		io_las_writer
		io_ogr_writer
		io_optech
		io_stac_reader
		io_tiledb_bit_fields
		io_tiledb_time_reader
		io_tiledb_time_writer
		io_tiledb_utils
		merge
		"
	case "$CARCH" in
		arm*|s390x|x86) tests="$tests
			utils
			filters_icp
			file_utils
			filters_assign
			" ;;
		x86_64|loongarch64) tests="$tests
			info
			" ;;

	esac
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)_test|icetest|random_test"
	msg "$skipped_tests"
	ctest --test-dir build --output-on-failure -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	cd $pkgdir/usr/lib
	rm libpdalcpp.so
	ln -s libpdalcpp.so.?? libpdalcpp.so
}

plugins() {
	amove usr/lib/libpdal_plugin_*.so.*
}

sha512sums="
d3b02f13e56423c5086e72908f932db384cb0d64f3d3e5cec121c1e283268f8e38f6123ff852d77c07ea9777001a78595bdafed458dc06aa52402d92e76ce995  PDAL-2.8.0-src.tar.bz2
"
